package cn.sf.sufingvideoconsumer.controller;

import cn.sf.pojo.Video;
import cn.sf.pojo.VideoClassify;
import cn.sf.sufingvideoconsumer.service.IndexService;
import com.alibaba.fastjson.JSON;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author sric
 */
@RestController
@CrossOrigin("*")
public class IndexController {
    @Resource
    private IndexService indexService;


    @RequestMapping("/indexVideo")
    public List<Video> indexVideo() {
        String redisQueryRandom = indexService.getRedisQueryRandom();
        List<Video> parseArray = JSON.parseArray(redisQueryRandom, Video.class);
        return parseArray;
    }

    @RequestMapping("/getVideoClassiFy")
    public List<VideoClassify> getVideoClassiFy() {
        List<VideoClassify> videoClassifies = indexService.queryVideoClassify();
        return videoClassifies;
    }


    /**
     * 根据视频分类查询视频信息
     * @param primary 一级分类
     * @param classification 二级分类
     * @param sort 排序
     * @return
     */
    @RequestMapping("/getClassificationVideo")
    public List<Video> getClassificationVideo(Long primary,Long classification,Integer sort){
        List<Video> videos = indexService.classificationQueryVideo(primary,classification, sort);
        return videos;
    }

}
